<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 使用for循环封装函数还原filter函数
      let res = [1, 5, 8, 0, 3, 6, 8]
      Array.prototype.myFilter = function (getNum) {
        let arr = []
        for (let i = 0; i < this.length; i++) {
          // 如果回调函数的返回值是true，就把他加入到数组当中
          if (getNum(this[i], i, this)) {
            arr.push(this[i])
          }
        }
        return arr
      }
      let rt = res.myFilter((item, index, res) => {
        return item > 5
      })
      console.log(rt)
    </script>
  </body>
</html>
